﻿/*
 * Created by SharpDevelop.
 * User: IEscarro
 * Date: 8/29/2009
 * Time: 12:58 PM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Collections.Generic;
using Buaya.Model;

namespace Buaya.Gui
{
	/// <summary>
	/// Description of SSSPremiumForm.
	/// </summary>
	public partial class SSSPremiumForm : BaseForm
	{
		public SSSPremiumForm() : this(new SSSPremium())
		{
			
		}
		
		public SSSPremiumForm(SSSPremium p)
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			Model = p;
		}
		
		protected override void OnModelChanged(EventArgs e)
		{
			base.OnModelChanged(e);
			SSSPremium p = Model as SSSPremium;
			textBoxCode.Text = p.Code;
			textBoxRangeFrom.Text = p.RangeFrom.ToString("0.00");
			textBoxUpTo.Text = p.RangeTo.ToString("0.00");
			textBoxER.Text = p.ER.ToString("0.00");
			textBoxEC.Text = p.EC.ToString("0.00");
			textBoxEE.Text = p.EE.ToString("0.00");
			textBoxContribution.Text = p.Contribution.ToString("0.00");
			checkBoxInactive.Checked = p.Inactive;
		}
		
		void ButtonOkClick(object sender, EventArgs e)
		{
			SSSPremium p = Model as SSSPremium;
			p.Code = textBoxCode.Text;
			p.RangeFrom = Util.ConvertUtility.ToDouble(textBoxRangeFrom.Text);
			p.RangeTo = Util.ConvertUtility.ToDouble(textBoxUpTo.Text);
			p.ER = Util.ConvertUtility.ToDouble(textBoxER.Text);
			p.EC = Util.ConvertUtility.ToDouble(textBoxEC.Text);
			p.EE = Util.ConvertUtility.ToDouble(textBoxEE.Text);
			p.Contribution = Util.ConvertUtility.ToDouble(textBoxContribution.Text);
			p.Inactive = checkBoxInactive.Checked;
			SessionFacade.SaveOrUpdateSSSPremium(p);
			Close();
		}
		
		void ButtonCancelClick(object sender, EventArgs e)
		{
			Close();
		}
	}
}
